"""
资产基类模块 - 定义资产基类
"""

from abc import ABC, abstractmethod
from typing import Dict, List, Optional, Union, Any
import pandas as pd
import logging

# 导入常量
from FDAS.data.constants import (
    ASSET_TYPE_STOCK,
    ASSET_TYPE_FUTURE,
    ASSET_TYPE_OPTION,
    ASSET_TYPE_FUND,
    ASSET_TYPE_INDEX,
    ASSET_TYPE_ETF
)

class Asset(ABC):
    """资产基类"""
    
    def __init__(self, symbol: str, provider=None):
        """
        初始化资产
        
        参数:
            symbol: 资产代码
            provider: 数据提供者，如果为None则使用默认提供者
        """
        self.symbol = symbol
        self.logger = logging.getLogger(f"{self.__class__.__name__}({symbol})")
        
        # 延迟导入，避免循环依赖
        from FDAS.data.providers import default_provider
        self.provider = provider or default_provider
        
        # 缓存基本信息
        self._basic_info = None
    
    @property
    def basic_info(self) -> Dict[str, Any]:
        """获取资产基本信息"""
        if self._basic_info is None:
            self._basic_info = self._get_basic_info()
        return self._basic_info
    
    @abstractmethod
    def _get_basic_info(self) -> Dict[str, Any]:
        """获取资产基本信息的具体实现"""
        pass
    
    @abstractmethod
    def get_history(self, start_date: str = None, end_date: str = None, 
                   period: str = "daily", adjust: str = "qfq", 
                   limit: int = None) -> pd.DataFrame:
        """
        获取历史数据
        
        参数:
            start_date: 开始日期，格式：YYYYMMDD
            end_date: 结束日期，格式：YYYYMMDD
            period: 周期，可选值：daily, weekly, monthly
            adjust: 复权方式，可选值：qfq(前复权), hfq(后复权), ""(不复权)
            limit: 限制返回的数据条数
            
        返回:
            包含历史数据的DataFrame
        """
        pass
    
    def __str__(self) -> str:
        """字符串表示"""
        return f"{self.__class__.__name__}({self.symbol})"
    
    def __repr__(self) -> str:
        """对象表示"""
        return self.__str__()